package com.ccb.sc.common.modules.goods.service.impl;

import com.ccb.sc.common.modules.goods.service.IBrandService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccb.sc.common.bind.vo.KeyValueIconVo;
import com.ccb.sc.common.enums.ValidStatus;
import com.ccb.sc.common.modules.goods.entity.Brand;
import com.ccb.sc.common.modules.goods.mapper.BrandMapper;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 产品品牌 服务实现类
 * </p>
 *
 * @author ken
 * @since 2020-08-21
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {

    @Override
    public List<KeyValueIconVo> findAll() {
        List<Brand> list = this.list(new QueryWrapper<Brand>().lambda().eq(Brand::getStatus, ValidStatus.VALID));
        if (CollectionUtils.isEmpty(list)) {
            return Lists.newArrayList();
        }
        return list.stream().map(item -> {
            KeyValueIconVo vo = new KeyValueIconVo();
            vo.setKey(item.getId());
            vo.setValue(item.getName());
            vo.setIcon(item.getIcon());
            return vo;
        }).collect(Collectors.toList());
    }
}
